package org.movsim.movdroid;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkUtil {
	public static final String GET_URL = "http://sage.cs.uwp.edu/cs475/getScore.php";	// url for score submission
	public static final String SEND_URL = "http://sage.cs.uwp.edu/cs475/putScore.php";	// url for high score retrieval
	
	
	// returns true if Internet connection is available via Wifi or Mobile network, false otherwise
	public static boolean isNetworkAvailable(Context context) {
	    boolean haveConnectedWifi = false;	// boolean for Wifi connection, initially false
	    boolean haveConnectedMobile = false;	// boolean for Mobile connection, initially false

	    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // get handle to ConnectivityManager
	    NetworkInfo[] netInfo = cm.getAllNetworkInfo();	// get array of NetworkInfo objects from ConnectivityManager
	    for (NetworkInfo ni : netInfo) {	// loop through all NetworkInfo objects in array
	        if (ni.getTypeName().equalsIgnoreCase("WIFI"))	// if type is Wifi
	            if (ni.isConnected())	// if is connected
	                haveConnectedWifi = true;	// set Wifi connected to true
	        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))	// if type is Mobile
	            if (ni.isConnected())	// if is connected
	                haveConnectedMobile = true;	// set Mobile connected to true
	    }
	    
	    return haveConnectedWifi || haveConnectedMobile;	// return connected Wifi or connected Mobile detected
	}
}
